package cn.hh.wechatkit.pojo.message.imp;

import java.util.Map;

import cn.hh.wechatkit.pojo.message.Wx_IMsg;
import cn.hh.wechatkit.pojo.message.Wx_MsgTypeEnum;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;

/**
 * Created this one by HMH on 2017/5/6.
 * 基础消息
 */

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public abstract class Wx_BaseMsg implements Wx_IMsg {

    private String toUserName;
    private String fromUserName;
    private long createTime;
    private Wx_MsgTypeEnum msgType;
    private String msgId;

    /**
     * 构造消息对象
     * @param map xml解析结果
     */
    public Wx_BaseMsg(Map<String, String> map) {
        this.toUserName = map.get("ToUserName");
        this.fromUserName = map.get("FromUserName");
        this.createTime = Long.parseLong(map.get("CreateTime"));
        this.msgType = Wx_MsgTypeEnum.fromString(map.get("MsgType"),"卡券类型");
        this.msgId = map.get("MsgId");
    }

    /**
     * 生成回复消息
     */
    public Wx_IMsg getReverseMsg () {
        String tempName = this.toUserName;
        this.toUserName = this.fromUserName;
        this.fromUserName = tempName;
        this.createTime = new Date().getTime()/1000;
        return this;
    }
}
